home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / Envelope.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  23.5 KB  |  677 lines  |  [TEXT/KAHL]

  1. /* Envelope.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #define ShowMeEnvelopeRec
  31. #include "Envelope.h"
  32. #include "Memory.h"
  33. #include "Frequency.h"
  34.  
  35.  
  36. /* create a new envelope record with nothing in it */
  37. EnvelopeRec*                        NewEnvelope(void)
  38.     {
  39.         EnvelopeRec*                    Envelope;
  40.  
  41.         Envelope = (EnvelopeRec*)AllocPtrCanFail(sizeof(EnvelopeRec),"EnvelopeRec");
  42.         if (Envelope == NIL)
  43.             {
  44.              FailurePoint1:
  45.                 return NIL;
  46.             }
  47.         Envelope->PhaseArray = (EnvStepRec*)AllocPtrCanFail(0,"PhaseArray");
  48.         if (Envelope->PhaseArray == NIL)
  49.             {
  50.              FailurePoint2:
  51.                 ReleasePtr((char*)Envelope);
  52.                 goto FailurePoint1;
  53.             }
  54.         Envelope->SustainPhase1 = -1;
  55.         Envelope->SustainPhase2 = -1;
  56.         Envelope->SustainPhase3 = -1;
  57.         Envelope->SustainPhase1Type = eEnvelopeReleasePointNoSkip;
  58.         Envelope->SustainPhase2Type = eEnvelopeReleasePointNoSkip;
  59.         Envelope->SustainPhase3Type = eEnvelopeReleasePointNoSkip;
  60.         Envelope->Origin = 0;
  61.         Envelope->NumPhases = 0;
  62.         Envelope->OverallScalingFactor = 1;
  63.         return Envelope;
  64.     }
  65.  
  66.  
  67. /* dispose of an envelope record */
  68. void                                        DisposeEnvelope(EnvelopeRec* Envelope)
  69.     {
  70.         CheckPtrExistence(Envelope);
  71.         ReleasePtr((char*)Envelope->PhaseArray);
  72.         ReleasePtr((char*)Envelope);
  73.     }
  74.  
  75.  
  76. /* find out how many frames there are in the envelope */
  77. long                                        GetEnvelopeNumFrames(EnvelopeRec* Envelope)
  78.     {
  79.         CheckPtrExistence(Envelope);
  80.         return Envelope->NumPhases;
  81.     }
  82.  
  83.  
  84. /* set a release point.  -1 means this release point is ignored */
  85. void                                        EnvelopeSetReleasePoint1(EnvelopeRec* Envelope, long Release,
  86.                                                     SustainTypes ReleaseType)
  87.     {
  88.         CheckPtrExistence(Envelope);
  89.         ERROR((Release < -1) || (Release > Envelope->NumPhases),PRERR(ForceAbort,
  90.             "EnvelopeSetReleasePoint1:  release point is out of range"));
  91.         ERROR((ReleaseType != eEnvelopeSustainPointSkip)
  92.             && (ReleaseType != eEnvelopeReleasePointSkip)
  93.             && (ReleaseType != eEnvelopeSustainPointNoSkip)
  94.             && (ReleaseType != eEnvelopeReleasePointNoSkip),PRERR(ForceAbort,
  95.             "EnvelopeSetReleasePoint1:  bad release type"));
  96.         Envelope->SustainPhase1 = Release;
  97.         Envelope->SustainPhase1Type = ReleaseType;
  98.     }
  99.  
  100.  
  101. /* set a release point.  -1 means this release point is ignored */
  102. void                                        EnvelopeSetReleasePoint2(EnvelopeRec* Envelope, long Release,
  103.                                                     SustainTypes ReleaseType)
  104.     {
  105.         CheckPtrExistence(Envelope);
  106.         ERROR((Release < -1) || (Release > Envelope->NumPhases),PRERR(ForceAbort,
  107.             "EnvelopeSetReleasePoint2:  release point is out of range"));
  108.         ERROR((ReleaseType != eEnvelopeSustainPointSkip)
  109.             && (ReleaseType != eEnvelopeReleasePointSkip)
  110.             && (ReleaseType != eEnvelopeSustainPointNoSkip)
  111.             && (ReleaseType != eEnvelopeReleasePointNoSkip),PRERR(ForceAbort,
  112.             "EnvelopeSetReleasePoint2:  bad release type"));
  113.         Envelope->SustainPhase2 = Release;
  114.         Envelope->SustainPhase2Type = ReleaseType;
  115.     }
  116.  
  117.  
  118. /* set a release point.  -1 means this release point is ignored */
  119. void                                        EnvelopeSetReleasePoint3(EnvelopeRec* Envelope, long Release,
  120.                                                     SustainTypes ReleaseType)
  121.     {
  122.         CheckPtrExistence(Envelope);
  123.         ERROR((Release < -1) || (Release > Envelope->NumPhases),PRERR(ForceAbort,
  124.             "EnvelopeSetReleasePoint3:  release point is out of range"));
  125.         ERROR((ReleaseType != eEnvelopeSustainPointSkip)
  126.             && (ReleaseType != eEnvelopeReleasePointSkip)
  127.             && (ReleaseType != eEnvelopeSustainPointNoSkip)
  128.             && (ReleaseType != eEnvelopeReleasePointNoSkip),PRERR(ForceAbort,
  129.             "EnvelopeSetReleasePoint3:  bad release type"));
  130.         Envelope->SustainPhase3 = Release;
  131.         Envelope->SustainPhase3Type = ReleaseType;
  132.     }
  133.  
  134.  
  135. /* get the value of a release point */
  136. long                                        GetEnvelopeReleasePoint1(EnvelopeRec* Envelope)
  137.     {
  138.         CheckPtrExistence(Envelope);
  139.         return Envelope->SustainPhase1;
  140.     }
  141.  
  142.  
  143. /* get the value of a release point */
  144. long                                        GetEnvelopeReleasePoint2(EnvelopeRec* Envelope)
  145.     {
  146.         CheckPtrExistence(Envelope);
  147.         return Envelope->SustainPhase2;
  148.     }
  149.  
  150.  
  151. /* get the value of a release point */
  152. long                                        GetEnvelopeReleasePoint3(EnvelopeRec* Envelope)
  153.     {
  154.         CheckPtrExistence(Envelope);
  155.         return Envelope->SustainPhase3;
  156.     }
  157.  
  158.  
  159. /* get the release point type */
  160. SustainTypes                        GetEnvelopeReleaseType1(EnvelopeRec* Envelope)
  161.     {
  162.         CheckPtrExistence(Envelope);
  163.         return Envelope->SustainPhase1Type;
  164.     }
  165.  
  166.  
  167. /* get the release point type */
  168. SustainTypes                        GetEnvelopeReleaseType2(EnvelopeRec* Envelope)
  169.     {
  170.         CheckPtrExistence(Envelope);
  171.         return Envelope->SustainPhase2Type;
  172.     }
  173.  
  174.  
  175. /* get the release point type */
  176. SustainTypes                        GetEnvelopeReleaseType3(EnvelopeRec* Envelope)
  177.     {
  178.         CheckPtrExistence(Envelope);
  179.         return Envelope->SustainPhase3Type;
  180.     }
  181.  
  182.  
  183. /* set the origin of the envelope */
  184. void                                        EnvelopeSetOrigin(EnvelopeRec* Envelope, long Origin)
  185.     {
  186.         CheckPtrExistence(Envelope);
  187.         Envelope->Origin = Origin;
  188.     }
  189.  
  190.  
  191. /* get the origin from the envelope */
  192. long                                        GetEnvelopeOrigin(EnvelopeRec* Envelope)
  193.     {
  194.         CheckPtrExistence(Envelope);
  195.         return Envelope->Origin;
  196.     }
  197.  
  198.  
  199. void                                        EnvelopeSetAccent1Amp(EnvelopeRec* Envelope,
  200.                                                     double Val, long Phase)
  201.     {
  202.         CheckPtrExistence(Envelope);
  203.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  204.             "EnvelopeSetAccent1Amp:  index is out of range"));
  205.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  206.             sizeof(Envelope->PhaseArray[Phase]));
  207.         Envelope->PhaseArray[Phase].Accent1Amp = Val;
  208.     }
  209.  
  210.  
  211. void                                        EnvelopeSetAccent2Amp(EnvelopeRec* Envelope,
  212.                                                     double Val, long Phase)
  213.     {
  214.         CheckPtrExistence(Envelope);
  215.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  216.             "EnvelopeSetAccent2Amp:  index is out of range"));
  217.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  218.             sizeof(Envelope->PhaseArray[Phase]));
  219.         Envelope->PhaseArray[Phase].Accent2Amp = Val;
  220.     }
  221.  
  222.  
  223. void                                        EnvelopeSetAccent3Amp(EnvelopeRec* Envelope,
  224.                                                     double Val, long Phase)
  225.     {
  226.         CheckPtrExistence(Envelope);
  227.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  228.             "EnvelopeSetAccent3Amp:  index is out of range"));
  229.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  230.             sizeof(Envelope->PhaseArray[Phase]));
  231.         Envelope->PhaseArray[Phase].Accent3Amp = Val;
  232.     }
  233.  
  234.  
  235. void                                        EnvelopeSetAccent4Amp(EnvelopeRec* Envelope,
  236.                                                     double Val, long Phase)
  237.     {
  238.         CheckPtrExistence(Envelope);
  239.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  240.             "EnvelopeSetAccent4Amp:  index is out of range"));
  241.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  242.             sizeof(Envelope->PhaseArray[Phase]));
  243.         Envelope->PhaseArray[Phase].Accent4Amp = Val;
  244.     }
  245.  
  246.  
  247. void                                        EnvelopeSetFreqAmpRolloff(EnvelopeRec* Envelope,
  248.                                                     double Val, long Phase)
  249.     {
  250.         CheckPtrExistence(Envelope);
  251.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  252.             "EnvelopeSetFreqAmpRolloff:  index is out of range"));
  253.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  254.             sizeof(Envelope->PhaseArray[Phase]));
  255.         Envelope->PhaseArray[Phase].FrequencyAmpRolloff = Val;
  256.     }
  257.  
  258.  
  259. void                                        EnvelopeSetFreqAmpNormalization(EnvelopeRec* Envelope,
  260.                                                     double Val, long Phase)
  261.     {
  262.         CheckPtrExistence(Envelope);
  263.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  264.             "EnvelopeSetFreqAmpNormalization:  index is out of range"));
  265.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  266.             sizeof(Envelope->PhaseArray[Phase]));
  267.         Envelope->PhaseArray[Phase].FrequencyAmpNormalization = Val;
  268.     }
  269.  
  270.  
  271. void                                        EnvelopeSetAccent1Rate(EnvelopeRec* Envelope,
  272.                                                     double Val, long Phase)
  273.     {
  274.         CheckPtrExistence(Envelope);
  275.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  276.             "EnvelopeSetAccent1Rate:  index is out of range"));
  277.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  278.             sizeof(Envelope->PhaseArray[Phase]));
  279.         Envelope->PhaseArray[Phase].Accent1Rate = Val;
  280.     }
  281.  
  282.  
  283. void                                        EnvelopeSetAccent2Rate(EnvelopeRec* Envelope,
  284.                                                     double Val, long Phase)
  285.     {
  286.         CheckPtrExistence(Envelope);
  287.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  288.             "EnvelopeSetAccent2Rate:  index is out of range"));
  289.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  290.             sizeof(Envelope->PhaseArray[Phase]));
  291.         Envelope->PhaseArray[Phase].Accent2Rate = Val;
  292.     }
  293.  
  294.  
  295. void                                        EnvelopeSetAccent3Rate(EnvelopeRec* Envelope,
  296.                                                     double Val, long Phase)
  297.     {
  298.         CheckPtrExistence(Envelope);
  299.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  300.             "EnvelopeSetAccent3Rate:  index is out of range"));
  301.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  302.             sizeof(Envelope->PhaseArray[Phase]));
  303.         Envelope->PhaseArray[Phase].Accent3Rate = Val;
  304.     }
  305.  
  306.  
  307. void                                        EnvelopeSetAccent4Rate(EnvelopeRec* Envelope,
  308.                                                     double Val, long Phase)
  309.     {
  310.         CheckPtrExistence(Envelope);
  311.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  312.             "EnvelopeSetAccent4Rate:  index is out of range"));
  313.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  314.             sizeof(Envelope->PhaseArray[Phase]));
  315.         Envelope->PhaseArray[Phase].Accent4Rate = Val;
  316.     }
  317.  
  318.  
  319. void                                        EnvelopeSetFreqRateRolloff(EnvelopeRec* Envelope,
  320.                                                     double Val, long Phase)
  321.     {
  322.         CheckPtrExistence(Envelope);
  323.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  324.             "EnvelopeSetFreqRateRolloff:  index is out of range"));
  325.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  326.             sizeof(Envelope->PhaseArray[Phase]));
  327.         Envelope->PhaseArray[Phase].FrequencyRateRolloff = Val;
  328.     }
  329.  
  330.  
  331. void                                        EnvelopeSetFreqRateNormalization(EnvelopeRec* Envelope,
  332.                                                     double Val, long Phase)
  333.     {
  334.         CheckPtrExistence(Envelope);
  335.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  336.             "EnvelopeSetFreqRateNormalization:  index is out of range"));
  337.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  338.             sizeof(Envelope->PhaseArray[Phase]));
  339.         Envelope->PhaseArray[Phase].FrequencyRateNormalization = Val;
  340.     }
  341.  
  342.  
  343. EnvNumberType                        GetEnvelopeAccent1Amp(EnvelopeRec* Envelope, long Phase)
  344.     {
  345.         CheckPtrExistence(Envelope);
  346.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  347.             "GetEnvelopeAccent1Amp:  index is out of range"));
  348.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  349.             sizeof(Envelope->PhaseArray[Phase]));
  350.         return Envelope->PhaseArray[Phase].Accent1Amp;
  351.     }
  352.  
  353.  
  354. EnvNumberType                        GetEnvelopeAccent2Amp(EnvelopeRec* Envelope, long Phase)
  355.     {
  356.         CheckPtrExistence(Envelope);
  357.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  358.             "GetEnvelopeAccent2Amp:  index is out of range"));
  359.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  360.             sizeof(Envelope->PhaseArray[Phase]));
  361.         return Envelope->PhaseArray[Phase].Accent2Amp;
  362.     }
  363.  
  364.  
  365. EnvNumberType                        GetEnvelopeAccent3Amp(EnvelopeRec* Envelope, long Phase)
  366.     {
  367.         CheckPtrExistence(Envelope);
  368.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  369.             "GetEnvelopeAccent3Amp:  index is out of range"));
  370.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  371.             sizeof(Envelope->PhaseArray[Phase]));
  372.         return Envelope->PhaseArray[Phase].Accent3Amp;
  373.     }
  374.  
  375.  
  376. EnvNumberType                        GetEnvelopeAccent4Amp(EnvelopeRec* Envelope, long Phase)
  377.     {
  378.         CheckPtrExistence(Envelope);
  379.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  380.             "GetEnvelopeAccent4Amp:  index is out of range"));
  381.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  382.             sizeof(Envelope->PhaseArray[Phase]));
  383.         return Envelope->PhaseArray[Phase].Accent4Amp;
  384.     }
  385.  
  386.  
  387. EnvNumberType                        GetEnvelopeFreqAmpRolloff(EnvelopeRec* Envelope, long Phase)
  388.     {
  389.         CheckPtrExistence(Envelope);
  390.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  391.             "GetEnvelopeFreqAmpRolloff:  index is out of range"));
  392.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  393.             sizeof(Envelope->PhaseArray[Phase]));
  394.         return Envelope->PhaseArray[Phase].FrequencyAmpRolloff;
  395.     }
  396.  
  397.  
  398. EnvNumberType                        GetEnvelopeFreqAmpNormalization(EnvelopeRec* Envelope, long Phase)
  399.     {
  400.         CheckPtrExistence(Envelope);
  401.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  402.             "GetEnvelopeFreqAmpNormalization:  index is out of range"));
  403.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  404.             sizeof(Envelope->PhaseArray[Phase]));
  405.         return Envelope->PhaseArray[Phase].FrequencyAmpNormalization;
  406.     }
  407.  
  408.  
  409. EnvNumberType                        GetEnvelopeAccent1Rate(EnvelopeRec* Envelope, long Phase)
  410.     {
  411.         CheckPtrExistence(Envelope);
  412.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  413.             "GetEnvelopeAccent1Rate:  index is out of range"));
  414.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  415.             sizeof(Envelope->PhaseArray[Phase]));
  416.         return Envelope->PhaseArray[Phase].Accent1Rate;
  417.     }
  418.  
  419.  
  420. EnvNumberType                        GetEnvelopeAccent2Rate(EnvelopeRec* Envelope, long Phase)
  421.     {
  422.         CheckPtrExistence(Envelope);
  423.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  424.             "GetEnvelopeAccent2Rate:  index is out of range"));
  425.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  426.             sizeof(Envelope->PhaseArray[Phase]));
  427.         return Envelope->PhaseArray[Phase].Accent2Rate;
  428.     }
  429.  
  430.  
  431. EnvNumberType                        GetEnvelopeAccent3Rate(EnvelopeRec* Envelope, long Phase)
  432.     {
  433.         CheckPtrExistence(Envelope);
  434.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  435.             "GetEnvelopeAccent3Rate:  index is out of range"));
  436.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  437.             sizeof(Envelope->PhaseArray[Phase]));
  438.         return Envelope->PhaseArray[Phase].Accent3Rate;
  439.     }
  440.  
  441.  
  442. EnvNumberType                        GetEnvelopeAccent4Rate(EnvelopeRec* Envelope, long Phase)
  443.     {
  444.         CheckPtrExistence(Envelope);
  445.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  446.             "GetEnvelopeAccent4Rate:  index is out of range"));
  447.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  448.             sizeof(Envelope->PhaseArray[Phase]));
  449.         return Envelope->PhaseArray[Phase].Accent4Rate;
  450.     }
  451.  
  452.  
  453. EnvNumberType                        GetEnvelopeFreqRateRolloff(EnvelopeRec* Envelope, long Phase)
  454.     {
  455.         CheckPtrExistence(Envelope);
  456.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  457.             "GetEnvelopeFreqRateRolloff:  index is out of range"));
  458.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  459.             sizeof(Envelope->PhaseArray[Phase]));
  460.         return Envelope->PhaseArray[Phase].FrequencyRateRolloff;
  461.     }
  462.  
  463.  
  464. EnvNumberType                        GetEnvelopeFreqRateNormalization(EnvelopeRec* Envelope, long Phase)
  465.     {
  466.         CheckPtrExistence(Envelope);
  467.         ERROR((Phase < 0) || (Phase >= Envelope->NumPhases),PRERR(ForceAbort,
  468.             "GetEnvelopeFreqRateNormalization:  index is out of range"));
  469.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Phase]),
  470.             sizeof(Envelope->PhaseArray[Phase]));
  471.         return Envelope->PhaseArray[Phase].FrequencyRateNormalization;
  472.     }
  473.  
  474.  
  475. /* set the overall amplitude scaling factor */
  476. void                                        EnvelopeSetOverallAmplitude(EnvelopeRec* Envelope,
  477.                                                     double OverallAmplitude)
  478.     {
  479.         CheckPtrExistence(Envelope);
  480.         Envelope->OverallScalingFactor = OverallAmplitude;
  481.     }
  482.  
  483.  
  484. /* get the overall amplitude */
  485. EnvNumberType                        GetEnvelopeOverallAmplitude(EnvelopeRec* Envelope)
  486.     {
  487.         CheckPtrExistence(Envelope);
  488.         return Envelope->OverallScalingFactor;
  489.     }
  490.  
  491.  
  492. /* insert a new phase at the specified position.  Values are undefined */
  493. MyBoolean                                EnvelopeInsertPhase(EnvelopeRec* Envelope, long Index)
  494.     {
  495.         EnvStepRec*                        ArrayTemp;
  496.         long                                    Scan;
  497.  
  498.         CheckPtrExistence(Envelope);
  499.         ERROR((Index < 0) || (Index > Envelope->NumPhases),PRERR(ForceAbort,
  500.             "EnvelopeInsertPhase:  index is out of range"));
  501.  
  502.         ArrayTemp = (EnvStepRec*)ResizePtr((char*)Envelope->PhaseArray,
  503.             sizeof(EnvStepRec) * (Envelope->NumPhases + 1));
  504.         if (ArrayTemp == NIL)
  505.             {
  506.              FailurePoint1:
  507.                 return False;
  508.             }
  509.         Envelope->PhaseArray = ArrayTemp;
  510.  
  511.         /* now transfer the data in the arrays to make a hole */
  512.         for (Scan = Envelope->NumPhases - 1; Scan >= Index; Scan -= 1)
  513.             {
  514.                 PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Scan]),
  515.                     sizeof(Envelope->PhaseArray[Scan]));
  516.                 PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Scan + 1]),
  517.                     sizeof(Envelope->PhaseArray[Scan + 1]));
  518.                 Envelope->PhaseArray[Scan + 1] = Envelope->PhaseArray[Scan];
  519.             }
  520.         Envelope->PhaseArray[Index].Duration = 0;
  521.         Envelope->PhaseArray[Index].EndPoint = 0;
  522.         Envelope->PhaseArray[Index].TransitionType = eEnvelopeLinearInAmplitude;
  523.         Envelope->PhaseArray[Index].TargetType = eEnvelopeTargetAbsolute;
  524.         Envelope->PhaseArray[Index].Accent1Amp = 0;
  525.         Envelope->PhaseArray[Index].Accent2Amp = 0;
  526.         Envelope->PhaseArray[Index].Accent3Amp = 0;
  527.         Envelope->PhaseArray[Index].Accent4Amp = 0;
  528.         Envelope->PhaseArray[Index].FrequencyAmpRolloff = 0;
  529.         Envelope->PhaseArray[Index].FrequencyAmpNormalization = MIDDLEC;
  530.         Envelope->PhaseArray[Index].Accent1Rate = 0;
  531.         Envelope->PhaseArray[Index].Accent2Rate = 0;
  532.         Envelope->PhaseArray[Index].Accent3Rate = 0;
  533.         Envelope->PhaseArray[Index].Accent4Rate = 0;
  534.         Envelope->PhaseArray[Index].FrequencyRateRolloff = 0;
  535.         Envelope->PhaseArray[Index].FrequencyRateNormalization = MIDDLEC;
  536.         Envelope->NumPhases += 1;
  537.         return True;
  538.     }
  539.  
  540.  
  541. /* delete a phase from the envelope */
  542. void                                        EnvelopeDeletePhase(EnvelopeRec* Envelope, long Index)
  543.     {
  544.         long                                    Scan;
  545.  
  546.         CheckPtrExistence(Envelope);
  547.         /* since we don't use the length of the arrays for anything, we can leave */
  548.         /* the extra cell at the end and it won't hurt anything */
  549.         ERROR((Index < 0) || (Index > Envelope->NumPhases - 1),PRERR(ForceAbort,
  550.             "EnvelopeDeletePhase:  index is out of range"));
  551.         for (Scan = Index; Scan < Envelope->NumPhases - 1; Scan += 1)
  552.             {
  553.                 PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Scan]),
  554.                     sizeof(Envelope->PhaseArray[Scan]));
  555.                 PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Scan + 1]),
  556.                     sizeof(Envelope->PhaseArray[Scan + 1]));
  557.                 Envelope->PhaseArray[Scan] = Envelope->PhaseArray[Scan + 1];
  558.             }
  559.         Envelope->NumPhases -= 1;
  560.         if (Envelope->SustainPhase1 > Envelope->NumPhases)
  561.             {
  562.                 Envelope->SustainPhase1 = Envelope->NumPhases;
  563.             }
  564.         if (Envelope->SustainPhase2 > Envelope->NumPhases)
  565.             {
  566.                 Envelope->SustainPhase2 = Envelope->NumPhases;
  567.             }
  568.         if (Envelope->SustainPhase3 > Envelope->NumPhases)
  569.             {
  570.                 Envelope->SustainPhase3 = Envelope->NumPhases;
  571.             }
  572.         if (Envelope->Origin > Envelope->NumPhases)
  573.             {
  574.                 Envelope->Origin = Envelope->NumPhases;
  575.             }
  576.     }
  577.  
  578.  
  579. /* set a new value for the specified phase's duration */
  580. void                                        EnvelopeSetPhaseDuration(EnvelopeRec* Envelope, long Index,
  581.                                                     double Duration)
  582.     {
  583.         CheckPtrExistence(Envelope);
  584.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  585.             "EnvelopeSetPhaseDuration:  index is out of range"));
  586.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  587.             sizeof(Envelope->PhaseArray[Index]));
  588.         Envelope->PhaseArray[Index].Duration = Duration;
  589.     }
  590.  
  591.  
  592. /* get the duration from the specified envelope position */
  593. EnvNumberType                        GetEnvelopePhaseDuration(EnvelopeRec* Envelope, long Index)
  594.     {
  595.         CheckPtrExistence(Envelope);
  596.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  597.             "GetEnvelopePhaseDuration:  index is out of range"));
  598.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  599.             sizeof(Envelope->PhaseArray[Index]));
  600.         return Envelope->PhaseArray[Index].Duration;
  601.     }
  602.  
  603.  
  604. /* set a new value for the specified phase's ultimate value */
  605. void                                        EnvelopeSetPhaseFinalValue(EnvelopeRec* Envelope, long Index,
  606.                                                     double FinalValue)
  607.     {
  608.         CheckPtrExistence(Envelope);
  609.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  610.             "EnvelopeSetPhaseFinalValue:  index is out of range"));
  611.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  612.             sizeof(Envelope->PhaseArray[Index]));
  613.         Envelope->PhaseArray[Index].EndPoint = FinalValue;
  614.     }
  615.  
  616.  
  617. /* get the phase's ultimate value */
  618. EnvNumberType                        GetEnvelopePhaseFinalValue(EnvelopeRec* Envelope, long Index)
  619.     {
  620.         CheckPtrExistence(Envelope);
  621.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  622.             "GetEnvelopePhaseFinalValue:  index is out of range"));
  623.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  624.             sizeof(Envelope->PhaseArray[Index]));
  625.         return Envelope->PhaseArray[Index].EndPoint;
  626.     }
  627.  
  628.  
  629. /* set the value for a phase's transition type */
  630. void                                        EnvelopeSetPhaseTransitionType(EnvelopeRec* Envelope, long Index,
  631.                                                     EnvTransTypes TransitionType)
  632.     {
  633.         CheckPtrExistence(Envelope);
  634.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  635.             "EnvelopeSetPhaseTransitionType:  index is out of range"));
  636.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  637.             sizeof(Envelope->PhaseArray[Index]));
  638.         Envelope->PhaseArray[Index].TransitionType = TransitionType;
  639.     }
  640.  
  641.  
  642. /* obtain the value in a phase's transition type */
  643. EnvTransTypes                        GetEnvelopePhaseTransitionType(EnvelopeRec* Envelope, long Index)
  644.     {
  645.         CheckPtrExistence(Envelope);
  646.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  647.             "GetEnvelopePhaseTransitionType:  index is out of range"));
  648.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  649.             sizeof(Envelope->PhaseArray[Index]));
  650.         return Envelope->PhaseArray[Index].TransitionType;
  651.     }
  652.  
  653.  
  654. /* set the value for a phase's target type */
  655. void                                        EnvelopeSetPhaseTargetType(EnvelopeRec* Envelope, long Index,
  656.                                                     EnvTargetTypes TargetType)
  657.     {
  658.         CheckPtrExistence(Envelope);
  659.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  660.             "EnvelopeSetPhaseTargetType:  index is out of range"));
  661.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  662.             sizeof(Envelope->PhaseArray[Index]));
  663.         Envelope->PhaseArray[Index].TargetType = TargetType;
  664.     }
  665.  
  666.  
  667. /* get the target type for a phase */
  668. EnvTargetTypes                    GetEnvelopePhaseTargetType(EnvelopeRec* Envelope, long Index)
  669.     {
  670.         CheckPtrExistence(Envelope);
  671.         ERROR((Index < 0) || (Index >= Envelope->NumPhases),PRERR(ForceAbort,
  672.             "GetEnvelopePhaseTargetType:  index is out of range"));
  673.         PRNGCHK(Envelope->PhaseArray,&(Envelope->PhaseArray[Index]),
  674.             sizeof(Envelope->PhaseArray[Index]));
  675.         return Envelope->PhaseArray[Index].TargetType;
  676.     }
  677.